package com.tledu.springboot04.controller;

import com.tledu.springboot04.core.model.AjaxResult;
import com.tledu.springboot04.domain.Address;
import com.tledu.springboot04.service.IAddressService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@AllArgsConstructor
@RequestMapping("/address")
public class AddressController {
    private final IAddressService addressService;

    @GetMapping("/list")
    @ResponseBody
    public AjaxResult<List<Address>> select(Address address) {
        return new AjaxResult(addressService.list(address));
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult<Void> add(Address address) {
        addressService.insert(address);
        return new AjaxResult();
    }
}
